import http from '@/utils/http'
import type { ResType } from './shared'

// 1.定义泛型

// 2.定义接口

export type ChannelItems = {
  id: number
  name: string
}

type ChannelRes = {
  channels: ChannelItems[]
}

// 3.定义函数

export const getChannelListAPI = () => {
  return http.request<ResType<ChannelRes>>({
    url: '/channels',
    method: 'GET',
  })
}

// 文章列表api
type ListItem = {
  art_id: string
  title: string
  aut_id: string
  comm_count: number
  pubdate: string
  aut_name: string
  is_top: number
  cover: {
    type: number
    images: string[]
  }
}

export type ListRes = {
  results: ListItem[]
  pre_timestamp: string
}

type ReqParams = {
  channel_id: string
  timestamp: string
}

export const getListAPI = (params: ReqParams) => {
  return http.request<ResType<ListRes>>({
    url: '/articles',
    method: 'GET',
    params
  })
}
